import { Module } from '@nestjs/common';
import { BackgroundModule } from './modules/background.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as path from 'path';
import { ConfigModule, ConfigService } from 'nestjs-config';//读取env变量
import { RedisModule } from 'nestjs-redis';
@Module({
  imports: [
    // 配置加载配置文件
    ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}'), {
      modifyConfigName: (name: string) => name.replace('.config', ''),
    }),
    // mysql的连接
    TypeOrmModule.forRootAsync({
      useFactory: async (config: ConfigService) => ({
        type: config.get('database.type'),
        host: config.get('database.host'),
        port: config.get('database.port'),
        username: config.get('database.username'),
        password: config.get('database.password'),
        database: config.get('database.database'),
        entities: [__dirname + '/**/*.entity{.ts,.js}'],
        logging: config.get('database.logging'),//开启所有数据库信息打印
        logger: 'advanced-console', // 高亮字体的打印信息
        synchronize: true, // 同步数据库
        timezone: '+08:00', // 东八区
        cache: {
          duration: 60000, // 1分钟的缓存
        },
        extra: {
          poolMax: 32,
          poolMin: 16,
          queueTimeout: 60000,
          pollPingInterval: 60, // 每隔60秒连接
          pollTimeout: 60, // 连接有效60秒
        },
      }),
      inject: [ConfigService],
    }),
    // redis的连接
    RedisModule.register({  
      port: 6479,
      host: '49.235.173.77',
      password: 'wg123456l',
      db: 0,
      connectTimeout: 10000
    }),

    BackgroundModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule { }
